package com.school.repository;

import com.school.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findByUsername(String username);

    Optional<User> findByStudentId(String studentId);

    List<User> findByRole(String role);

    @Query("SELECT u FROM User u WHERE u.role = :role AND (u.username LIKE %:keyword% OR u.name LIKE %:keyword%)")
    List<User> findByRoleAndKeyword(@Param("role") String role, @Param("keyword") String keyword);

    List<User> findByRoleAndClassId(String role, Integer classId);
}
